package com.ecmcloud.flow.resource;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecmcloud.common.dto.Result;
import com.ecmcloud.common.dto.TaskParamDto;
import com.ecmcloud.common.dto.TaskResultDto;
import com.ecmcloud.common.dto.VariableQueryParamDto;
import com.ecmcloud.flow.service.WorkflowTaskService;

/**
 * 任务控制器
 */
@RestController
@RequestMapping("task")
public class TaskResource {

	@Autowired
	private WorkflowTaskService workflowTaskService;

	/**
	 * 查询任务变量
	 * 
	 * @param paramDto
	 * @return
	 */
	@PostMapping("queryTaskVariables")
	public Result<Map<String, Object>> queryTaskVariables(@RequestBody VariableQueryParamDto paramDto) {
		return Result.success(workflowTaskService.queryTaskVariables(paramDto));
	}

	/**
	 * 查询任务
	 *
	 * @param taskId
	 * @return
	 */
	@GetMapping("queryTask")
	public Result<TaskResultDto> queryTask(String taskId, String userId) {
		TaskResultDto taskResultDto = workflowTaskService.queryTask(taskId, userId);
		return Result.success(taskResultDto);
	}

	/**
	 * 完成任务
	 *
	 * @param taskParamDto
	 * @return
	 */
	@PostMapping("complete")
	public Result<String> complete(@RequestBody TaskParamDto taskParamDto) {
		workflowTaskService.complete(taskParamDto);
		return Result.success();
	}

}
